package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buba.service.ApproveService;
import common.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import entity.user.Approve;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 认证表 前端控制器
 * </p>
 *
 * @author ZL
 * @since 2022-11-12
 */
@RestController
@RequestMapping("/approve")
public class ApproveController {

    @Resource
    private ApproveService approveService;

    /**
     * 功能描述: 新增或更新
     *
     * @param approve
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/save")
    public R save(@RequestBody Approve approve) {
        approveService.saveOrUpdate(approve);
        return R.success();
    }

    /**
     * 功能描述: 删除
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        approveService.removeById(id);
        return R.success();
    }

    /**
     * 功能描述: 批量删除
     *
     * @param ids
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        approveService.removeByIds(ids);
        return R.success();
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(approveService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(approveService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: zl
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<Approve> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(approveService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}
